define(function () {
    'use strict';
    function ctrl($scope,$state, $ionicLoading,LocalCacheService, CommonService,FinancingService) {
        function init() {
            $scope.user = LocalCacheService.getUser();

            $scope.financing = {
                money: 0,
                dollar: 2000.00
            };
            $scope.financingAccountList = [{
                name: '可借金额',
                money: 0,
                dollar: 3000.00
            }, {
                name: '还款金额',
                money: 0,
                dollar: 2000.00
            }];

            var params = {client_id: $scope.user.client_id, fund_account: $scope.user.fund_account};
            $ionicLoading.show();
            FinancingService.getIndexInfo(params).then(function (data) {
                $ionicLoading.hide();
                if (data.error_no!= '-1') {
                    $scope.financing.money=data.enable_balance;
                    $scope.financing.checkCsdcTimeFlag=data.checkCsdcTimeFlag
                    $scope.financingAccountList[0].money=data.enable_balance;
                    $scope.financingAccountList[1].money=data.repayment_amount;

                }
            });


            var rate = ($scope.financingAccountList[1].money / ($scope.financingAccountList[1].money+$scope.financingAccountList[0].money)) * 100;
            $('#indicatorContainer').radialIndicator({
                barColor: '#ffa94a',
                barBgColor:'#6d91d2',
                barWidth: 6,
                initValue: rate,
                radius:74,
                displayNumber: false
            });
        }

        $scope.$on('$ionicView.loaded', function () {
            init();
        });

        $scope.loan=function(){
            //非交易时间弹出提示，“尊敬的用户！非交易时间无法交易，请知悉”！
            if($scope.financing.checkCsdcTimeFlag==0){
                CommonService.showConfig({message:"尊敬的用户！非交易时间无法交易，请知悉!"});
                return false;
            }
            //当无额度时，点击弹出对话框“尊敬的客户！您暂无可质押股票，请先购买或转入，成功后于第二个工作日开始可以进行质押申请，如有疑问请联系客服：400-800-5000”；
            if($scope.financing.money<=0){
                CommonService.showConfig({message:"尊敬的客户！您暂无可质押股票，请先购买或转入，成功后于第二个工作日开始可以进行质押申请，如有疑问请联系客服：400-800-5000。"});
                return false;
            }
            //满足条件后跳转
            $state.go('tab.account-easyFinancingIntelligenceLoan');
        }
    }

    ctrl.$inject = ['$scope', '$state', '$ionicLoading', 'LocalCacheService', 'CommonService', 'FinancingService'];
    return ctrl;
});